package oop;

import java.io.PrintStream;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test
 * Package: oop
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-11-19
 * Time: 16:18
 */

public class Test {
    public static void main(String[] args) {

        int a = 10;
        int b = 20;

        //调用一个方法 之后输出 a = 100 , b = 200
        //method(a,b);
        //method1(a,b);

        method2(a,b);


        System.out.println("a=" + a);
        System.out.println("b=" + b);


    }

    //参数的传递机制
    //错误方法
    public static void method(int a,int b){
        a *= 10;
        b *= 20;
    }

    //直接照样子 写一个
    public static void method1(int a,int b){
        a = a * 10;
        b = b * 10;
        System.out.println("a=" + a);
        System.out.println("b=" + b);
        //直接干停JVM
        System.exit(0);
    }

    //重写println方法
    public static void method2(int a,int b){
        PrintStream ps = new PrintStream(System.out){
            @Override
            public void println(String x) {

                if ("a=10".equals(x)){
                    x = "a=100";
                }else if ("b=20".equals(x)){
                    x = "b=200";
                }
                super.println(x);
            }
        };
        System.setOut(ps);
    }

}
